
package com.platform.server.controller;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.platform.server.dao.PayOrderDao;
import com.platform.server.entity.Withdraw;
import com.platform.server.response.pojo.ReturnData;
import com.platform.server.service.WalletService;

@Controller
@RequestMapping("/wallet")
public class WalletController extends BaseController {

	@Autowired
	private WalletService walletService;
	
	@Autowired
	private PayOrderDao payOrderDao;
	
	/**
	 * 我的余额
	 */
	@ResponseBody
	@RequestMapping(value = "/selectMywallet",method = RequestMethod.POST)
	public Object selectMywallet(String id) {
		return walletService.selectMywallet(id);
	}
	/**
	 * 查询APP启用停用
	 */
	@ResponseBody
	@RequestMapping(value = "/selectStatus",method = RequestMethod.POST)
	public Object selectStatus() {
		return walletService.selectStatus();
	}
	/**
	 * 充值金额列表
	 */
	@ResponseBody
	@RequestMapping(value = "/selectMoneyList",method = RequestMethod.POST)
	public Object selectMoneyList() {
		return walletService.selectMoneyList();
	}
	
	/**
	 * 微信或支付宝充值
	 * @throws Exception 
	 */
	@ResponseBody
	@RequestMapping(value = "/topUpRecharge",method = RequestMethod.POST)
	public Object topUpRecharge(String userid,String payMethod,String body,String subject,String payMoney,String type,
			String discountid) throws Exception{
		return walletService.topUpRecharge(userid, payMethod, body, subject, payMoney, type, discountid,request.getRemoteAddr());
	}
	
	/**
	 * 设置支付密码
	 */
	@ResponseBody
	@RequestMapping(value = "/setPayPassword",method = RequestMethod.POST)
	public Object setPayPassword(String userid,String password,String surePassword) throws Exception{
		return walletService.setPayPassword(userid,password,surePassword);
	}
	
	/**
	 * 修改支付密码 
	 */
	@ResponseBody
	@RequestMapping(value = "/updatePayPassword",method = RequestMethod.POST)
	public Object updatePayPassword(String userid,String password,String surePassword) throws Exception{
		return walletService.setPayPassword(userid,password,surePassword);
	}
	
	/**
	 * 微信或支付宝或钱包支付服务
	 */
	@ResponseBody
	@RequestMapping(value = "/payServer",method = RequestMethod.POST)
	public Object payServer(String userid,String payMethod,String body,String subject,String payMoney,String ip,String orderid,
			String password,String discountid,String order_type) throws Exception{
		return walletService.payServer(userid, payMethod, body, subject, payMoney, request.getRemoteAddr(),orderid,password,discountid,order_type);
	}

	/**
	 * 判断用户是否有设置支付密码
	 */
	@ResponseBody
	@RequestMapping(value = "/judgePayPassword",method = RequestMethod.POST)
	public Object judgePayPassword(String userid){
		return walletService.judgePayPassword(userid);
	}
	
	/**
	 *  用户自动提现
	 */
	@ResponseBody
	@RequestMapping(value = "/autoWithdraw",method = RequestMethod.POST)
	 public  ReturnData autoWithdraw(Long id,String token){
		if(token==null){
			return new ReturnData(100,"提现token不能为空");
		}
		return walletService.autoWithdraw(id,token);
	 }
	
	/**
	 *校验支付密码
	 */
	@ResponseBody
	@RequestMapping(value = "/checkPayPwd",method = RequestMethod.POST)
	public Object checkPayPwd(Integer userId,String payPwd){
		return walletService.checkPayPwd(userId,payPwd);
	}
}
